package org.wms.minbearwcs.dao.inbound.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import org.wms.minbearwcs.dao.inbound.inf.InboundOrderDetailDao;
import org.wms.minbearwcs.entity.Mapper.inbound.InboundOrderDetailMapper;
import org.wms.minbearwcs.entity.PO.wcs.inbound.InboundOrderDetail;
import org.wms.minbearwcs.entity.PO.wcs.inbound.status.InboundOrderDetailStatus;

@Repository
@RequiredArgsConstructor
public class InboundOrderDetailDaoImpl implements InboundOrderDetailDao {

    private final InboundOrderDetailMapper mapper;

    @Override
    public boolean insert(InboundOrderDetail inboundOrderDetail) {
        return mapper.insert(inboundOrderDetail) == 1;
    }

    @Override
    public InboundOrderDetail selectDetailByOrderCodeAndPalletCode(String orderCode, String palletCode, InboundOrderDetailStatus status) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(InboundOrderDetail::getInboundOrderCode,orderCode)
                .eq(InboundOrderDetail::getPalletCode,palletCode)
                .eq(InboundOrderDetail::getStatus,status)
                .one();
    }

    @Override
    public boolean updateStartPointById(Integer id, String startPoint) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(InboundOrderDetail::getId,id)
                .set(InboundOrderDetail::getStartPoint,startPoint)
                .update();
    }

    @Override
    public boolean updateStatusById(Integer id, InboundOrderDetailStatus status) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(InboundOrderDetail::getId,id)
                .set(InboundOrderDetail::getStatus,status)
                .update();
    }

    @Override
    public InboundOrderDetailStatus getStatusById(Integer id) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(InboundOrderDetail::getId,id)
                .select(InboundOrderDetail::getStatus)
                .one()
                .getStatus();
    }

    @Override
    public boolean updateStoragePointById(Integer id,String storagePoint) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(InboundOrderDetail::getId,id)
                .set(InboundOrderDetail::getStoragePoint,storagePoint)
                .update();
    }

    @Override
    public boolean updateExchangePointById(Integer id, String exchangePoint) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(InboundOrderDetail::getId,id)
                .set(InboundOrderDetail::getExchangePoint,exchangePoint)
                .update();
    }

    @Override
    public boolean updateLiftRequestPoint(Integer id, String liftRequestPoint) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(InboundOrderDetail::getId,id)
                .set(InboundOrderDetail::getLiftRequestPoint,liftRequestPoint)
                .update();
    }

    @Override
    public InboundOrderDetail selectDetailByOrderCodeAndPalletCode(String palletCode, InboundOrderDetailStatus status) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(InboundOrderDetail::getPalletCode,palletCode)
                .eq(InboundOrderDetail::getStatus,status)
                .one();
    }

    @Override
    public InboundOrderDetail selectById(Integer id) {
        return mapper.selectById(id);
    }
}
